package fieldmaps.algebra;
//package fieldmaps.mapalgebra;
//
//import com.vividsolutions.jts.geom.Polygon;
//
//import fieldmaps.database.DatabaseRasterMap;
//import fieldmaps.exceptions.MapAlgebraException;
//import fieldmaps.mapalgebra.callback.ICallbackBinary;
//import fieldmaps.mapalgebra.callback.ICallbackUnary;
//import fieldmaps.types.RasterMapInfo;
//
//public class FieldMap {
//	
////	private static Logger LOGGER = Logger.getLogger(GenericFieldMap.class);
//	private RasterMapRepository repository;
//
//	public FieldMap(RasterMapRepository repository) {
//		this.repository = repository;
//	}
//	
//	public void BinaryOperation(FieldMap otherMap, ICallbackBinary callback) throws MapAlgebraException {
////		if (otherMap.repository.get.doubleValue() != map2.getMapArea().doubleValue()) {
////			throw new MapAlgebraException("Invalid maps! Both areas must be equal!");
////		}
////		
//		Polygon polygon;
//		RasterMapInfo mapInfo = new RasterMapInfo(repository.);
//		DatabaseRasterMap newMap = DatabaseRasterMap.createMap(mapInfo, callbackObject.newMapName());
////
////		try {
////			while ((polygon = map1.getNextCell()) != null) {
////				List<Polygon> polygonsIntersection = new LinkedList<Polygon>();
////				List<Double> areasPolygonsIntersection = new LinkedList<Double>();
////				map2.getPolygonsIntersectionArea(polygon, polygonsIntersection, areasPolygonsIntersection);
////				Object interpolatedValue = getInterpolatedValue (polygon, polygonsIntersection, areasPolygonsIntersection);
////				Integer userData = (Integer) callbackObject.doOperation(interpolatedValue, polygon.getUserData());
////				newMap.addCell(polygon.getCoordinates(), userData);
////			}
////		} catch (NoSuchElementException e) {
////			LOGGER.info("New map: " + callbackObject.newMapName() + " successfully created!");
////			return newMap;
////		} catch (SQLException e) {
////			LOGGER.error(e.getMessage());
////		}
////		map1.resetCellIteration();
////		return null;
//	}
//
////	private Object getInterpolatedValue(Polygon polygon, List<Polygon> polygonsIntersection, List<Double> areasPolygonsIntersection) {
////		Double polygonArea = polygon.getArea();
////		Integer polygonValue = (Integer)polygon.getUserData(); 
////		if (polygonValue == map1.getMapInfo().getNodata()) {
////			return null;
////		}
////		Integer polygonsIntersectionSize = polygonsIntersection.size();
////		if (polygonsIntersectionSize == 1) {
////			return (int)(polygonArea / polygonsIntersection.get(0).getArea()) * (Integer)polygonsIntersection.get(0).getUserData(); 
////		}
////		Double value = 0.0;
////		Polygon p;
////		for (int i = 0; i < polygonsIntersectionSize; i++) {
////			p = polygonsIntersection.get(i);
////			if ((Integer)p.getUserData() == map2.getMapInfo().getNodata()) {
////				return null;
////			}
////			value += (areasPolygonsIntersection.get(i) / p.getArea()) * (Integer)p.getUserData();		
////		}
////		return (new Long(Math.round(value))).intValue();
////	}
//	
//	public void UnaryOperation(ICallbackUnary callback) {
//		
//	}
//}
